'''
Request URL: https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=51029114960
&score=0&sortType=5&page=0&pageSize=10&isShadowSku=0&fold=1
'''

import re
import requests

url = 'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=51029114960&score=0&sortType=5&page={}&pageSize=10&isShadowSku=0&fold=1'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
}

# 定义用于接收数据的列表
commodity_Color,  commodity_Comments,  commodity_Name,  commodity_Time,  commodity_name = [], [], [], [], []

for index in range(0, 1):
    #通过requests模块获取到网页信息
    content = requests.get(url=url.format(index), headers=headers)
    #用户名
    commodity_Name += re.findall(r'","nickname":"(.*?)","', content.text)
    #时间：
    commodity_Time += re.findall(r'","creationTime":"(.*?)","', content.text)
    #产品名称：
    commodity_name += re.findall(r'","referenceName":"(.*?)","', content.text)
    #评论：
    commodity_Comments+= re.findall(r'","content":"(.*?)","', content.text)
    #规格
    commodity_Color += re.findall(r'"productColor":"(.*?)","', content.text)
    Info = [commodity_Color,  commodity_Comments,  commodity_Name,  commodity_Time,  commodity_name]
    for i in range(0, len(commodity_name)):
        print(commodity_Color[i],commodity_Comments[i], commodity_Name[i],  commodity_Time[i],commodity_name[i])
    print(commodity_Time)




